//
//  MyselfHeaderView.m
//  Lucky28
//
//  Created by zr on 2018/8/1.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "MyselfHeaderView.h"


@interface MyselfHeaderView ()

@property(nonatomic, weak)UIImageView * iconImageView;
@property(nonatomic, weak)UILabel * nameLabel;
@property(nonatomic, weak)UIImageView * backImageView;
@property(nonatomic, weak)UIImageView * topImageView;
@property(nonatomic, strong)UILabel * likeLabel;
@property(nonatomic, strong)UILabel * getLikeLabel;
@property(nonatomic, strong)UILabel * collectionLabel;
@property(nonatomic, strong)UILabel * likeValueLabel;
@property(nonatomic, strong)UILabel * getLikeValueLabel;
@property(nonatomic, strong)UILabel * collectionValueLabel;
@property(nonatomic, strong)UIView * oneLineView;
@property(nonatomic, strong)UIView * twoLineView;

@end

@implementation MyselfHeaderView


- (void)setUrl:(NSURL *)url{
    
    _url = url;
    
    [self.iconImageView sd_setImageWithURL:url placeholderImage:ImageNamed(@"头像7")];
}

-(void)setNameString:(NSString *)nameString{
    
    _nameString = nameString;
    
    self.nameLabel.text = nameString;
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    
    self.backgroundColor = [UIColor whiteColor];
    
    UIImageView * topImageView = [UIImageView new];
    
    topImageView.image = ImageNamed(@"bj-1");
    
    self.topImageView = topImageView;
    
    [self addSubview:self.topImageView];
    
    
    UIImageView * backImageView = [UIImageView new];
    
    backImageView.image = ImageNamed(@"yinyingkuang");
    
    self.backImageView = backImageView;
    
    [self addSubview:self.backImageView];
    
    UIImageView * iconImageView = [UIImageView new];
    
    //  给图片加一个圆形边框
    iconImageView.layer.borderWidth = 1.5f;//边框宽度
    iconImageView.layer.borderColor = ColorWithRGB(0xFAAFB9).CGColor;//边框颜色
    //  把图片设置成圆形
    iconImageView.layer.cornerRadius = 40 * SCREENH6;//裁成圆角
    iconImageView.layer.masksToBounds = YES;//隐藏裁剪掉的部分

//    iconImageView.image = ImageNamed(@"头像7");
    
    self.iconImageView = iconImageView;
    
    [self.backImageView addSubview:self.iconImageView];
    
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.text = @"用户姓名";
    nameLabel.textColor = [UIColor blackColor];
    nameLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.nameLabel = nameLabel;
    
    [self.backImageView addSubview:self.nameLabel];
    
    
    self.likeLabel = [self setupLabelWith:@"我赞过的"];
    [self.backImageView addSubview:self.likeLabel];
    
    self.getLikeLabel = [self setupLabelWith:@"获得的赞"];
    [self.backImageView addSubview:self.getLikeLabel];
    
    self.collectionLabel = [self setupLabelWith:@"我收藏的"];
    [self.backImageView addSubview:self.collectionLabel];
    
    self.likeValueLabel = [self setupLabelWith:@"0"];
    [self.backImageView addSubview:self.likeValueLabel];
    
    self.getLikeValueLabel = [self setupLabelWith:@"0"];
    [self.backImageView addSubview:self.getLikeValueLabel];
    
    self.collectionValueLabel = [self setupLabelWith:@"0"];
    [self.backImageView addSubview:self.collectionValueLabel];
    
    self.oneLineView = [self setupLineView];
    [self.backImageView addSubview:self.oneLineView];
    
    self.twoLineView = [self setupLineView];
    [self.backImageView addSubview:self.twoLineView];
}


- (void)layoutSubviews{
    
    [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(self);
        make.height.mas_equalTo(155 * SCREENH6);
    }];
    
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(90 * SCREENH6);
        make.height.mas_equalTo(151 * SCREENH6);
        make.leading.mas_equalTo(self).offset(30 * SCREENH6);
        make.trailing.mas_equalTo(self).offset(-30 * SCREENH6);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(80 * SCREENH6);
        make.leading.mas_equalTo(self.backImageView).offset(30 * SCREENH6);
        make.bottom.mas_equalTo(self.backImageView.mas_top).offset(60 * SCREENH6);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.backImageView).offset(15 * SCREENH6);
    }];
    
    [self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backImageView).offset(20 * SCREENH6);
        make.top.mas_equalTo(self.iconImageView.mas_bottom).offset(25 * SCREENH6);
    }];
    
    [self.likeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.likeLabel);
        make.top.mas_equalTo(self.likeLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.oneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(1 * SCREENH6);
        make.top.mas_equalTo(self.likeLabel).offset(8 * SCREENH6);
        make.bottom.mas_equalTo(self.likeValueLabel).offset(-5 * SCREENH6);
        make.leading.mas_equalTo(self).offset(SCREEN_WIDTH / 3);
    }];
    
    [self.getLikeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.backImageView);
        make.centerY.mas_equalTo(self.likeLabel);
    }];
    
    [self.getLikeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.getLikeLabel);
        make.top.mas_equalTo(self.getLikeLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.twoLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.bottom.top.mas_equalTo(self.oneLineView);
        make.leading.mas_equalTo(self).offset(SCREEN_WIDTH / 3 * 2);
    }];
    
    [self.collectionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.backImageView).offset(-20 * SCREENH6);
        make.centerY.mas_equalTo(self.getLikeLabel);
    }];
    
    [self.collectionValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.collectionLabel);
        make.top.mas_equalTo(self.collectionLabel.mas_bottom).offset(10 * SCREENH6);
    }];
}


- (UILabel *)setupLabelWith:(NSString *)string{
    
    UILabel * label = [UILabel new];
    
    label.text = string;
    label.textColor = ColorWithRGB(0x909090);
    label.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    
    return label;
}

- (UIView *)setupLineView{
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0x909090);
    
    
    return lineView;
}


@end
